package com.jiangSheng.mall.app.services.impl;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jiangSheng.mall.app.bean.CalcAmount;
import com.jiangSheng.mall.app.bean.ConfirmOrder;
import com.jiangSheng.mall.app.bean.ShoppingCar;
import com.jiangSheng.mall.app.dao.ReceiverAddressMapper;
import com.jiangSheng.mall.app.dao.ShoppingCarMapper;
import com.jiangSheng.mall.app.services.ShoppingCarServices;
@Transactional
@Service
public class ShoppingCarServicesImpl implements ShoppingCarServices{

	@Autowired
	private ShoppingCarMapper shoppingCarMapper;
	
	@Autowired
	private ReceiverAddressMapper receiverAddressMapper;
	
	@Override
	public int scSave(ShoppingCar shoppingCar) {
		return shoppingCarMapper.scSave(shoppingCar);
	}

	@Override
	public List<ShoppingCar> scList(Integer id) {
		return shoppingCarMapper.scList(id);
	}

	@Override
	public int scAlter(ShoppingCar shoppingCar) {
		return shoppingCarMapper.scAlter(shoppingCar);
	}

	@Override
	public int scMove(List<Integer> ids) {
		return shoppingCarMapper.scMove(ids);
	}

	@Override
	public ConfirmOrder scSettleAndGenerateConfirmOrder(List<Integer> ids) {
		ConfirmOrder confirmOrder = new ConfirmOrder();
		confirmOrder.setCalcAmount(calcAmount(getScListById(ids)));
		confirmOrder.setReceiverAddressList(receiverAddressMapper.getList());
		confirmOrder.setShoppingCarList(getScListById(ids));
		return confirmOrder;
	}

	@Override
	public List<ShoppingCar> getScListById(List<Integer> ids) {
		return shoppingCarMapper.getScListById(ids);
	}

	
	public CalcAmount calcAmount(List<ShoppingCar> ShoppingCars) {
		CalcAmount calcAmount = new CalcAmount();
		BigDecimal totalAmount = new BigDecimal(0);
		for (ShoppingCar shoppingCar : ShoppingCars) {
			totalAmount = totalAmount.add(shoppingCar.getShoppingCarPrice());
		}
		calcAmount.setFreightAmount(new BigDecimal(0));
		calcAmount.setTotalAmount(totalAmount);
		calcAmount.setPayAmount(totalAmount);
		
		return null;
	}
}
